package com.pda.common_easy.pages.modpass;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatButton;

import com.pda.common_easy.R;
import com.pda.common_easy.pages.login.LoginActivity;
import com.pda.common_easy.pages.main.MainActivity;
import com.public_module.basemvp.activity.BaseActivity;
import com.public_module.tools.SharedPreferencesManger;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ModfiyPassActivity extends BaseActivity<PageModel, PageView, PagePresent> implements PageView {
    @BindView(R.id.login1)
    EditText login1;
    @BindView(R.id.login2)
    EditText login2;
    @BindView(R.id.login3)
    EditText login3;
    @BindView(R.id.btlogin)
    AppCompatButton btlogin;
    @BindView(R.id.tvRes)
    TextView tvRes;
    @BindView(R.id.iv_title_left)
    ImageView ivTitleLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rltitle)
    RelativeLayout rltitle;

    String op = "";
    String np = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mp);
        ButterKnife.bind(this);
        tvTitle.setText("修改密码");
    }

    @Override
    public PageModel createModel() {
        return new PageModelImpl(this);
    }

    @Override
    public PageView createView() {
        return this;
    }

    @Override
    public PagePresent createPresenter() {
        return new PagePresent();
    }

    @Override
    public void tip(final String str) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                tvRes.setText(str);
            }
        });
    }

    @OnClick({R.id.iv_title_left, R.id.btlogin})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_title_left:
                finish();
                break;
            case R.id.btlogin:
                op = login1.getText().toString();
                if (op.length() == 0) {
                    showMsg("请填写旧密码");
                    return;
                }
                np = login2.getText().toString();
                if (np.length() == 0) {
                    showMsg("请填写新密码");
                    return;
                }
                if(np.equals(login3.getText().toString())){
                    presenter.config(op, np);
                }else {
                    showMsg("确认密码与新密码不一致");
                    return;
                }
                break;
        }
    }

    @Override
    protected void onDestroy() {
        if(SharedPreferencesManger.getUpass().equals("000000")){
            MainActivity.mainActivity.finish();
            intentToActivityWithoutParameter(this, LoginActivity.class);
        }
        super.onDestroy();
    }
}
